<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type = "text" onkeyup = "Myonkeyup()">

</body>
<script>
//键盘事件
    //1.onkeydown(不区分大小写)  
    // let input = document.querySelector("input");
    // input.onkeydown = function(event){
    //     console.log("你正在按下键盘!");
    //     let x = event.keyCode;
    //     //console.log(x);
    //     let y = String.fromCharCode(x);
    //     console.log(y);
    //};

    //2.onkeypress(区分大小写)
    let input = document.querySelector("input");
    input.onkeypress = function(event){
        console.log("你正在按下键盘!");
        let x = event.keyCode;
        //console.log(x);
        let y = String.fromCharCode(x);
        console.log(y);
        if(event.shiftKey)
            alert("Shift被按下");
        if(event.altKey)
            alert("Alt被按下");
    };

    //3.onkeyup
    function Myonkeyup()
    {
        console.log("按键被抬起!");
    }
</script>
</html>